import {defineStore} from 'pinia'

export const useCounterStore = defineStore('chooseArr', {
    state: () => {
        return {
            info: {
                product_category: [],
                product_material: [],
                product_purity: [],
                product_set: [],
                product_skn: [],
                product_technology: []
            },
            checkList: []
        }
    },

    // could also be defined as
    // state: () => ({ count: 0 })
    actions: {
        change(value) {
            // console.log(val)
            this.info = value;
        },
        remove(index) {
            const item = this.checkList[index];
            this.info[item.key][[item.index]].check = false;
            this.info[item.key]=this.info[item.key];
            this.checkList = this.checkList.filter((ele, index1) => {
                return index != index1
            })

        },
        changeCheckByIndexAndKey({key, index}) {
            this.info[key].forEach((ele, index1) => {
                if (index == index1) {
                    ele.check = !ele.check;
                } else {
                    ele.check = false;
                }
            })
            // console.log(this.info)

            this.info = this.info;
            this.checkList = [
                ...this.info.product_category.filter(ele => ele.check),
                ...this.info.product_material.filter(ele => ele.check),
                ...this.info.product_purity.filter(ele => ele.check),
                ...this.info.product_set.filter(ele => ele.check),
                ...this.info.product_skn.filter(ele => ele.check),
                ...this.info.product_technology.filter(ele => ele.check),
            ]
        }
    },
})